package Key_Value类型

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object partitionBy {
    //对pairRDD进行分区操作，如果原有的partionRDD和现有的partionRDD是一致的话就不进行分区， 否则会生成ShuffleRDD，即会产生shuffle过程。
    def main(args: Array[String]): Unit = {

        val config: SparkConf = new SparkConf().setMaster("local[*]").setAppName("WordCount")

        val sc = new SparkContext(config)

        val rdd = sc.parallelize(Array((1, "aaa"), (2, "bbb"), (3, "ccc"), (4, "ddd")), 4)

        rdd.collect().foreach(println)

        rdd.glom().foreach(array => {
            println(array.mkString(" "))
        })

        var rdd2 = rdd.partitionBy(new org.apache.spark.HashPartitioner(2))

        rdd2.glom().foreach(array => {
            println(array.mkString(" "))
        })

    }

}
